home *** CD-ROM | disk | FTP | other *** search
- /*
- * Variables controlling Yak settings.
- * Routines for initialisation at startup.
- */
-
- #include <exec/types.h>
- #include <dos/dos.h>
- #include <dos/dosextens.h>
- #include <libraries/commodities.h>
- #include <proto/dos.h>
- #include <proto/exec.h>
- #include <string.h>
-
- #include "yak.h"
- #include "hotkey_types.h"
- #include "gui.h"
- #define CATCOMP_NUMBERS
- #include "locale/yak_locale_strings.h"
-
- #ifdef _SAS
- extern struct DosLibrary *DOSBase;
- #endif
-
- /* local prototypes */
- static __regargs BOOL FWriteLong(BPTR fh, LONG n);
- static __regargs BOOL FReadLong(BPTR fh, LONG *n);
- static __regargs BOOL FWriteString(BPTR fh, char *buf);
- static __regargs BOOL FReadString(BPTR fh, char *buf, LONG len);
- static void LoadHotKeys(void);
- static void SaveHotKeys(void);
-
- #define DEF_AUTOPOINT_DELAY 2
- LONG autopoint_delay = DEF_AUTOPOINT_DELAY; /* used for autopoint */
-
- #define DEF_VOLUME 48
- LONG click_volume = DEF_VOLUME; /* used for keyclick */
-
- #define DEF_BLANKSECS 300
- LONG blanksecs = DEF_BLANKSECS;
- LONG blanktimeout;
- LONG blankcount; /* countdown to blank-time */
-
- #define DEF_MBLANKSECS 5
- LONG mouseblank = MB_SPRITES;
- LONG mblanksecs = DEF_MBLANKSECS;
- LONG mblanktimeout;
- LONG mblankcount; /* countdown to mouse-blank-time */
-
-
- TOGGLEDATA toggles[] = { /* -1 means UNUSED */
- TRUE, GDX_CTFCheck, ROOT_WINDOW,
- TRUE, GDX_CTBCheck, ROOT_WINDOW,
- TRUE, GDX_AutoCheck, ROOT_WINDOW,
- FALSE, GDX_KeyActCheck, ROOT_WINDOW,
- TRUE, GDX_ScrCycleCheck, ROOT_WINDOW,
- FALSE, GDX_AutoPopCheck, ROOT_WINDOW,
- FALSE, GDX_RMBActCheck, ROOT_WINDOW,
- FALSE, -1, NO_WINDOW,
- FALSE, -1, NO_WINDOW,
- FALSE, GDX_WildStarCheck, MISC_WINDOW,
- TRUE, GDX_ScrActCheck, ROOT_WINDOW,
- FALSE, GDX_NoClickCheck, MISC_WINDOW,
- FALSE, GDX_MMBActCheck, ROOT_WINDOW,
- FALSE, GDX_BlackBorderCheck, MISC_WINDOW,
- TRUE, GDX_BlankMouseOnKey, BLANK_WINDOW,
- FALSE, GDX_MMBShiftCheck, ROOT_WINDOW
- };
-
- PATTERNDATA patterns[NUM_PATTERNS] = {
- { "#?", NULL }, /* autoactivation screens */
- { "#?", NULL }, /* click screens */
- { "~(Workbench)", NULL }, /* autopop windows */
- { "~(Workbench)", NULL } /* click windows */
- };
-
- /* 1.5 format
- * Routines to load/save config file for Yak.
- * Should handle config files in upward-compatible manner.
- * File format:
- *
- * LONG ID
- * LONG NUM_TOGGLES
- * BOOL toggles
- * LONG NUM_HOTKEYS **REMOVED @ v1.5
- * STR hotkey1 '\n' :
- * : :
- * STR hotkeyN '\n' :
- * LONG NUM_PATTERNS
- * STR pattern1 '\n'
- * :
- * STR patternN '\n'
- * STR popcommand '\n' **REMOVED @ v1.5
- * STR datefmt '\n' **REMOVED @ v1.5
- * LONG click_volume, blanksecs
- * LONG mblanksecs **ADDED @ v1.3b
- * LONG mouseblank **ADDED @ v1.3e
- */
-
- #define CONFIG_ID 0x594b3135 /* YK15 */
-
- /* write a LONG to a file (in binary format) - returns success*/
- static __regargs BOOL
- FWriteLong(BPTR fh, LONG n)
- {
- return (BOOL)(FWrite(fh, (UBYTE *)&n, sizeof(LONG), 1) == 1);
- }
-
- /* read a LONG to a file (in binary format) - returns success */
- static __regargs BOOL
- FReadLong(BPTR fh, LONG *n)
- {
- return (BOOL)(FRead(fh, (UBYTE *)n, sizeof(LONG), 1) == 1);
- }
-
- /* write a string to a file (in binary format) - returns success*/
- /* '\n' is appended */
- static __regargs BOOL
- FWriteString(BPTR fh, char *buf)
- {
- FPuts(fh, buf);
- FPutC(fh, '\n');
- return (BOOL)(IoErr() == 0);
- }
-
- /* read a string to a file (in binary format) - returns success */
- /* '\n' is stripped and buf null-terminated; assumes dest large enough */
- static __regargs BOOL
- FReadString(BPTR fh, char *buf, LONG len)
- {
- FGets(fh, buf, len-1);
- buf[strlen(buf)-1] = '\0'; /* '\n' --> '\0' */
- return (BOOL)(IoErr() == 0);
- }
-
- /* save current settings to config file */
- void
- SaveSettings()
- {
- BPTR fh;
- UWORD i;
-
- if (fh = Open(CONFIG_FILE, MODE_NEWFILE))
- {
- FWriteLong(fh, CONFIG_ID);
-
- /* toggles */
- FWriteLong(fh, NUM_TOGGLES);
- for (i = 0; i < NUM_TOGGLES; i++)
- FWrite(fh, (UBYTE *)&toggles[i].pos, sizeof(BOOL), 1);
-
- /* patterns */
- FWriteLong(fh, NUM_PATTERNS);
- for (i = 0; i < NUM_PATTERNS; i++)
- FWriteString(fh, patterns[i].patstr);
-
- /* miscellaneous */
- FWriteLong(fh, click_volume);
- FWriteLong(fh, blanksecs);
- FWriteLong(fh, mblanksecs);
- FWriteLong(fh, mouseblank);
- FWriteLong(fh, autopoint_delay);
-
- Close(fh);
- }
-
- SaveHotKeys();
- }
-
-
-
- /* load current settings from file */
- void
- LoadSettings()
- {
- BPTR fh;
- UWORD i;
- LONG n;
-
- if (fh = Open(CONFIG_FILE, MODE_OLDFILE))
- {
- FReadLong(fh, &n);
- if (n == CONFIG_ID)
- {
- /* toggles */
- FReadLong(fh, &n);
- for (i = 0; i < n; i++)
- FRead(fh, (UBYTE *)&toggles[i].pos, sizeof(BOOL), 1);
-
- /* patterns */
- FReadLong(fh, &n);
- for (i = 0; i < n; i++)
- FReadString(fh, patterns[i].patstr, PATLEN+1);
-
- /* miscellaneous */
- FReadLong(fh, &click_volume);
- FReadLong(fh, &blanksecs);
- if (!FReadLong(fh, &mblanksecs)) /* none there */
- mblanksecs = DEF_MBLANKSECS;
- if (!FReadLong(fh, &mouseblank)) /* none there */
- mouseblank = MB_SPRITES;
- if (!FReadLong(fh, &autopoint_delay)) /* none there */
- autopoint_delay = DEF_AUTOPOINT_DELAY;
- }
- else PostError(getString(Invalid_config_file_ERR));
- Close(fh);
- }
- DeleteYakHotKeyList(); /* delete old keys */
- LoadHotKeys(); /* and load new ones */
-
- /* set-up patterns */
- for (i = 0; i < NUM_PATTERNS; i++)
- InitPattern(NULL, i);
-
- if (wildstar)
- WILDSTARON;
- else
- wildstar = ((struct RootNode *)(((struct DosLibrary *)DOSBase)->dl_Root))->rn_Flags & RNF_WILDSTAR;
-
-
- if (noclick) SetClickDrive(noclick);
-
- if (blackborder) ToggleBlackBorder(blackborder);
-
- if (mmbshift) ToggleMMBShift(mmbshift);
-
- blankcount = blanktimeout = 10*blanksecs;
- mblankcount = mblanktimeout = 10*mblanksecs;
- }
-
- /*
- * HOTKEY FILE FORMAT
- *
- * LONG ID 'YKK1'
- * LONG NUM_HOTKEYS
- * UWORD type1
- * UWORD opts1
- * STR hotkey1 '\n'
- * STR argstr1 '\n'
- * :
- * STR hotkeyN '\n'
- */
- #define HOTKEY_ID 0x594B4B31 /* 'YKK1' */
-
- static void
- SaveHotKeys()
- {
- YakHotKey *yhk;
- BPTR fh;
- UWORD type, i;
-
- if (fh = Open(HOTKEY_FILE, MODE_NEWFILE))
- {
- FWriteLong(fh, HOTKEY_ID);
-
- FWriteLong(fh, num_hkeys);
-
- for (type = 0; type < NUM_HOTKEY_TYPES; type++)
- for (yhk = (YakHotKey *)keylist(type)->lh_Head, i = 0;
- i < numkeys(type);
- i++, yhk = (YakHotKey *)yhk->yhk_Node.ln_Succ)
- {
- FWrite(fh, (UBYTE *)&yhk->yhk_Type, sizeof(UWORD), 1);
- FWrite(fh, (UBYTE *)&yhk->yhk_Options, sizeof(UWORD), 1);
- FWriteString(fh, yhk->yhk_KeyDef);
- FWriteString(fh, yhk->yhk_ArgStr ? yhk->yhk_ArgStr : "");
- }
-
- Close(fh);
- }
- }
-
- static void
- LoadHotKeys()
- {
- YakHotKey *yhk;
- char *buf;
- UWORD type, opts;
- BPTR fh;
- LONG n;
- UWORD i;
-
-
- DEBUG_BEGIN("LoadHotKeys()");
-
- if (!(buf = AllocVec(512, 0L)))
- {
- PostError(getString(No_memory_ERR));
- return;
- }
-
- if (fh = Open(HOTKEY_FILE, MODE_OLDFILE))
- {
- FReadLong(fh, &n);
-
- if (n == HOTKEY_ID)
- {
- FReadLong(fh, &n);
-
- DEBUG_PRINTF(" n = %d\n",n);
-
- for (i = 0; i < n; i++)
- {
-
- DEBUG_PRINTF(" i = %d\n",i);
-
- if (FRead(fh, (UBYTE *)&type, sizeof(UWORD), 1) &&
- FRead(fh, (UBYTE *)&opts, sizeof(UWORD), 1))
- {
-
- DEBUG_PRINTF(" type = %d\n",type);
- DEBUG_PRINTF(" opts = %d\n",opts);
-
- if ((type >= NUM_HOTKEY_TYPES) || (type < 0))
- {
- /* ignore key definition */
- FReadString(fh, buf, 512);
- FReadString(fh, buf, 512);
- continue;
- }
- else
- {
- if (yhk = NewYakHotKey(type))
- {
- yhk->yhk_Options = opts;
- FReadString(fh, buf, 512);
-
- DEBUG_PRINTF(" buf = %s\n",buf);
-
- if (ModifyYHKKeyDef(yhk, buf))
- {
-
- FReadString(fh, buf, 512);
- if (!buf[0] || ModifyYHKArgStr(yhk, buf))
- {
- continue;
- }
- }
- } /* end if (yhk = NewYakHotKey(type)) */
-
- } /* end else ((type >= NUM_HOTKEY_TYPES) || (type < 0)) */
-
- } /* end if FRead (opts, type) */
-
- } /* end for */
- }
- else
- {
- PostError(getString(Error_reading_hotkey_file_ERR));
-
- } /* end if (n == HOTKEY_ID) */
-
-
- DEBUG_PRINTF("num_hkeys = %d\n",num_hkeys);
-
- Close(fh);
-
- } /* end if fh */
-
- FreeVec(buf);
- }
-